package com.wcar.store.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wcar.common.entity.Station;
import com.wcar.common.entity.Store;
import com.wcar.common.entity.User;
import com.wcar.common.util.OssUtil;
import com.wcar.common.util.WebUtil;
import com.wcar.common.vo.Result;
import com.wcar.store.service.StationService;
import com.wcar.store.vo.StationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @BelongsProject: four-wcar-idea
 * @BelongsPackage: com.wcar.store.controller
 * @Author: 李睢康
 * @CreateTime: 2024-05-24  10:21
 */
@RestController
@RequestMapping("/store/station")
public class StationController {
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Resource
    private StationService stationService;
    @GetMapping("/info")
    public User hello(){
        //获取token
        String token = WebUtil.getToken();
        ValueOperations<String, String> forValue = redisTemplate.opsForValue();
        String s = forValue.get("user:login:" + token);
        User user = JSON.parseObject(s, User.class);
        return user;
    }
    @PostMapping("/getStationAll")
    public Result<IPage> stantion(@RequestBody StationVo stationVo){
        return stationService.selectStatinAll(stationVo);
    }

    @GetMapping("/selectStoreByUserId")
    public Result<List<Store>> findStore(){
        return stationService.selectStoreAll();
    }

    @PostMapping("/api/uploadFile")
    public Result<String> img(MultipartFile file){
        String s = OssUtil.uploadOss(file);
        return new Result<String>(200,"上传成功",s);
    }
    @PostMapping("/api/insertStation")
    public Result<String> insertStation(@RequestBody Station station){
        return stationService.insertStan(station);
    }
    @PostMapping("api/updateStation")
    public Result<String> updateStan(@RequestBody Station station){
        return stationService.updateSta(station);
    }

    @GetMapping("/api/deleteStationByStation")
    public Result<String> deleteSta(Integer station){
        return stationService.deleteSta(station);
    }
    @PostMapping("/api/selectByStoreId")
    public Result<List<Station>> findByStoreId(Integer storeId){
        return stationService.selectByStoreId(storeId);
    }
}
